yjx.controller('supportController', ['$rootScope', '$scope', '$compile', '$timeout', '$fetch', 'modalService', '$locals', function ($rootScope, $scope, $compile, $timeout, $fetch, modalService, $locals) {
    var api = '/support/getSupport'
    var params = {
        limit: 10,
        offset: 1,
    }
    //var page = $locals.get('page');
    //var resourceList = $locals.get('supportList')
    //if (page && resourceList) {
    //    var listArr = eval('[' + resourceList + ']');
    //    //console.log(listArr)
    //    $scope.resourceList = listArr;
    //
    //    $timeout(function () {
    //            var pageJ = JSON.parse(page)
    //            $scope.paging = pageJ.paging;
    //            $scope.pageNum = pageJ.pageNum ? pageJ.pageNum : 1;
    //            $scope.hideShows = pageJ.hideShows ? pageJ.hideShows : true;
    //            //$scope._updated = pageJ._updated;
    //        }
    //    )
    //} else {
    //
    //}
//$scope.paging = {};//不要初始化paging对象会导致更新状态在一开始为nomore
    $scope.pageNum = 1;
    $scope.hideShows = true;
    //$scope._update = false;

    function getResource() {
        $fetch.fetch(
            api,
            {
                params: params,
                cache:false,
            }

        ).then(function (data) {
                $timeout(function () {
                    $scope.paging = data.page;
                    $scope.resourceList = data.rows;
                    //更新状态、数据加载控制
                    $scope._updated = 'reupdated';
                    $scope.hideShows = false;

                    //if ($scope.resourceList && $scope.resourceList.length > 0) {
                    //    var arrStr = JSON.stringify($scope.resourceList);
                    //    $locals.set('supportList', arrStr.substr(1, arrStr.length - 2));
                    //    var page = {
                    //        'pageNum': $scope.pageNum,
                    //        'paging': $scope.paging,
                    //        '_updated': $scope._updated,
                    //        'hideShows': $scope.hideShows,
                    //    }
                    //    $locals.set('page', JSON.stringify(page));
                    //}

                })
            }).catch(function (e) {
                modalService.mainMsgError(e.msg);
            })
    }
    getResource();

      /*翻页处理*/
    $scope.list = function () {
        params.offset = $scope.pageNum;
        $fetch.fetch(
            api,
            {
                params: params,
                cache:false,
            }
        ).then(function (data) {
                $timeout(function () {
                    $scope.paging = data.page;
                    $scope.resourceList = $scope.resourceList.concat(data.rows);
                    //if ($locals.get('supportList')) {
                    //    $locals.remove('supportList')
                    //    var arrStr = JSON.stringify($scope.resourceList);
                    //    //console.log(arrStr);
                    //    $locals.set('supportList', arrStr.substr(1, arrStr.length - 2));
                    //} else {
                    //    var arrStr = JSON.stringify($scope.resourceList);
                    //    $locals.set('supportList', arrStr.substr(1, arrStr.length - 2));
                    //}
                    //更新状态、数据加载控制
                    $scope._updated = 'updated';
                    $scope.hideShows = false;

                    //var page = {
                    //    'pageNum': $scope.pageNum,
                    //    'paging': $scope.paging,
                    //    '_updated': $scope._updated,
                    //    'hideShows': $scope.hideShows,
                    //}
                    //$locals.remove('page')
                    //$locals.set('page', JSON.stringify(page));
                })
            }).catch(function (e) {
                modalService.mainMsgError(e.msg);
            })
    }



    //$scope.onClick = function(id){
    //    var length = $scope.resourceList.length;
    //    for(var i= 0; i<length;i++){
    //        if($scope.resourceList[i].id ==id){
    //            $scope.resourceList[i].clickTimes=$scope.resourceList[i].clickTimes+1 ;
    //            break;
    //        }
    //    }
    //}

}])